package cn.buyclss.backend.controller.shop;

import cn.buyclss.backend.entity.domain.shop.Shop;
import cn.buyclss.backend.entity.po.shop.ShopPO;
import cn.buyclss.backend.entity.support.RespResult;
import cn.buyclss.backend.entity.vo.shop.ShopVO;
import cn.buyclss.backend.service.shop.ShopService;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: Cecurio
 * @create: 2019-03-11 21:59
 **/
@RestController
@RequestMapping("/shop")
@Api(value = "商铺", description = "商铺")
public class ShopController {
    private Logger logger = LoggerFactory.getLogger(ShopController.class);

    @Autowired
    private ShopService shopService;

    @GetMapping("/all")
    @RequiresRoles("admin")
    @ApiOperation(value = "获取所有", notes = "获取所有. 操作者角色：管理员")
    public RespResult all() {
        return shopService.getAll();
    }

    @GetMapping("/page")
    @RequiresRoles("admin")
    @ApiOperation(value = "分页获取", notes = "分页获取. 操作者角色：管理员")
    public RespResult page(Integer pageIndex, Integer pageSize) {
        return shopService.page(pageIndex, pageSize);
    }

    @PostMapping("/applyOpenShop")
    @RequiresRoles("shop")
    @ApiOperation(value = "申请开店", notes = "只有商户才可以申请，一个商户只能开一个店，系统管理员不可以")
    public RespResult applyOpenShop(@RequestBody ShopVO shopVO) {
        logger.info(shopVO.toString());
        return shopService.addOne(shopVO);
    }


    @GetMapping("/myshop")
    @RequiresRoles("shop")
    @ApiOperation(value = "查看我的店铺", notes = "只有商户才可以操作")
    @ApiImplicitParam(paramType = "header", name = "Authorization", required = true)
    public RespResult fetchMyShop() {
        return shopService.getMyShop();
    }

//    @PostMapping("/x")
//    @ApiOperation(value = "",notes = "")
//    public RespResult x(){
//        RespResult res=null;
//        return res;
//    }

    // 管理员端
    //TODO 查看所有商家
    //TODO 查看所有商家的商品
    //TODO 查看所有商家的订单
}
